home *** CD-ROM | disk | FTP | other *** search
- /*
- Mix protocol echo client.
- Shows the usage of OpenConnection().
- Just a simple echo client, but it wants as second argument
- the string "TCP" or "UDP".
- To try this on localhost be sure your echo/tcp and echo/udp
- services are enabled in the inetd database.
- Then just write
- - rx echomix localhost tcp
- - rx echomix localhost udp
- */
-
- if ~show("L","rexxsupport.library") then
- if ~addlib("rexxsupport.library",0,-30) then do
- say "no rexxsupport.library"
- exit
- end
- if ~show("L","rxsocket.library") then
- if ~addlib("rxsocket.library",0,-30) then do
- say "no rxsocket.library"
- exit
- end
- if ~show("L","rmh.library") then
- if ~addlib("rmh.library",0,-30) then do
- say "no rmh.library"
- exit
- end
-
- prg = ProgramName("NOEXT")
-
- if ~RMH_ReadArgs("HOST/A,PROTO/A") then do
- call PrintFault(IoErr(),prg)
- exit
- end
- if parm.1.value~="tcp" & parm.1.value~="udp" then call err "PROTO must be 'tcp' or 'udp'"
-
- sock=OpenConnection(parm.1.value,"echo",parm.0.value)
- if sock<0 then
- select
- when sock==-5 then call err "echomix: can't bind socket on port."
- when sock==-4 then call err "echomix: service echo not found."
- when sock==-3 then call err "echomix: service not found."
- when sock==-2 then call err "echomix: host <" || parm.0.value || "> not found."
- when sock==-1 then call "echomix: unable to connect <"parm.0.value":echo> (" || errno() || ")"
- end
-
- request="echo service test"
- if send(sock,request)~=length(REQUEST) then
- call err "echomix: send error (" || errno() || ")"
-
- len=recv(sock,"BUF",256)
- if len<0 then call err "echomix: recv error (" || errno() || ")"
-
- say buf
- call CloseSocket(sock)
- exit
-
- err:
- parse arg msg
- say prg":" msg
- exit